package com.netty.learn.server;

import java.io.IOException;
import java.net.Socket;

/**
 * @Author: JohnCoding
 * @Description:
 * @date: 2020/8/21 22:20
 */
public class Client {

    private static final String HOST = "127.0.0.1";

    private static final int PORT = 8000;

    private static final int SLEEP_TIME = 5000;

    public static void main(String[] args) throws IOException{
        Socket socket = new Socket(HOST,PORT);

        new Thread(() -> {
            System.out.println("客户端启动成功");
            try {
                while (true) {
                    String msg = "hello world";
                    System.out.println("客户端发送消息："+ msg);
                    socket.getOutputStream().write(msg.getBytes());
                    Thread.sleep(SLEEP_TIME);
                }
            } catch (IOException | InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
    }
}
